var dtGridColumns = [{
    id: 'state',
    title: '读取状态',
    type: 'string',
    columnClass: 'text-center',
    headerStyle: 'color:grey;',
    resolution: function (value) {
        switch (value) {
            case '0':
                return '未读';
                break;
            case '1':
                return '已读';
                break;
        }
    }
}, {
    id: 'deviceRegisterName',
    title: '所有人',
    type: 'String',
    columnClass: 'text-center',
    headerStyle: 'color:grey; white-space:nowrap;'
}, {
    id: 'deviecBrand',
    title: '设备品牌',
    type: 'String',
    columnClass: 'text-center',
    headerStyle: 'color:grey; white-space:nowrap;'
}, {
    id: 'plateNum',
    title: '设备牌编号',
    type: 'String',
    columnClass: 'text-center',
    headerStyle: 'color:grey; white-space:nowrap;'
}, {
    id: 'machineryType',        //实例对象的字段
    title: '机械类型',           //表头
    type: 'string',             //数据格式
    columnClass: 'text-center', //单元格格式
    headerStyle: 'color:grey; white-space:nowrap;', //主题
    resolution: function (value) {
        switch (value) {
            case '0':
                return '挖掘机';
                break;
            case '1':
                return '装载机';
                break;
            case '2':
                return '矿用自卸车';
                break;
            case '3':
                return '推土机';
                break;
            case '4':
                return '压路机';
                break;
            case '5':
                return '平地机';
                break;
            case '6':
                return '混凝土机械';
                break;
            case '7':
                return '桩工机械';
                break;
            case '8':
                return '凿岩机械';
                break;
            case '9':
                return '摊铺机';
                break;
            case '10':
                return '俩头忙';
                break;
            case '11':
                return '旋挖钻';
                break;
            case '12':
                return '叉车';
                break;
            case '13':
                return '塔式起重机';
                break;
        }
    }
}, {
    id: 'plateSubject',
    title: '设备型号',
    type: 'string',
    columnClass: 'text-center',
    headerStyle: 'color:grey;',
}, {
    id: 'issure',
    title: '保险',
    type: 'string',
    columnClass: 'text-center',
    headerStyle: 'color:grey;',
    resolution: function (value) {
        switch (value) {
            case '1':
                return '有';
                break;
            case '2':
                return '无';
                break;
        }
    }
}, {
    id: 'mortgage',
    title: '抵押状态',
    type: 'string',
    columnClass: 'text-center',
    headerStyle: 'color:grey;',
    resolution: function (value) {
        switch (value) {
            case '0':
                return '未抵押';
                break;
            case '1':
                return '已抵押';
                break;
        }
    }
}, {
    id: 'createDate',
    title: '创建时间',
    type: 'date',
    /*format: 'yyyy-MM-dd',
    otype: 'time_stamp_ms',
    oformat: 'string',*/
    columnClass: 'text-center',
    headerStyle: 'color:grey;',
    // hideType: 'xs|sm|md|lg'
}, {
    id: 'operation',
    title: '操作',
    type: 'string',
    columnClass: 'text-center tpl-table-black-operation',
    headerStyle: 'color:grey; white-space:nowrap; padding: 0px 60px;',
    resolution: function (value, record, column, grid, dataNo, columnNo) { //此处的值（value）不直接显示
        var content = '';
        content += /*'<a href="#" onclick="loadPage(\'deviceInformation/' + record.id + '/select\');"> <i class="am-icon-pencil"></i>编辑</a> ' +
            '<a href="#" onclick="loadPage(\'deviceInformation/' + record.id + '/editState\');"> <i class="am-icon-pencil"></i>读取状态编辑</a> ' +*/
            '<a href="#" onclick="loadPage(\'deviceInformation/' + record.id + '/details\');"> <i class="am-icon-pencil"></i>设备详情</a> ' +
            '<a href="#" onclick="loadPage(\'deviceInformation/' + record.id + '/machinery\');"> <i class="am-icon-pencil"></i>档案证打印</a> ' +
            '<a href="#" onclick="loadPage(\'deviceInformation/' + record.factoryNum + '/statement\');"> <i class="am-icon-pencil"></i>声明书打印</a> ' +
            '<a href="#" onclick="loadPage(\'deviceInformation/' + record.factoryNum + '/entrust\');"> <i class="am-icon-pencil"></i>委托书打印</a> ' +
            '<a href="#" onclick="loadPage(\'deviceInformation/' + record.factoryNum + '/register\');"> <i class="am-icon-pencil"></i>备案表打印</a> ' +
            '<a href="#" onclick="loadPage(\'deviceInformation/' + record.factoryNum + '/transfer\');"> <i class="am-icon-pencil"></i>转移表打印</a> ' +
            '<a href="#" onclick="loadPage(\'deviceInformation/' + record.id + '/logo\');"> <i class="am-icon-pencil"></i>备案登记标志</a> ';
        return content;
    }
}];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    check: true,
    checkWidth: '37px',
    loadURL: 'deviceInformation/list',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    tools: '',
    pageSize:10, //默认每页十条记录
    pageSizeLimit: [10, 20, 30] //分页选项：每页10、20\或者30条记录
};
var grid = $.fn.dlshouwen.grid.init(dtGridOption);


$(function () {
    grid.load();
    $('select').selected();
});

function search() {
    grid.parameters = new Object();
    grid.parameters['deviec_brand'] = $("#deviceBrand").val();
    //var type = document.getElementById("select").value;
    grid.parameters['machinery_type'] = document.getElementById("type").value;
    grid.refresh(true);
}

function delteAll() {
    var checkId = getCheckAll(grid.getCheckedRecords());
    if (checkId != '') {
        del("deviceInformation/" + checkId + "/deleteBatch", search);
    } else {
        layer.msg('请选择要删除的数据', {
            icon: 3
        });
    }
}
function btnEdit(){
    var rows = grid.getCheckedRecords();
    if (rows.length == 1) {
        loadPage('deviceInformation/'+rows[0].id+'/select');
    }else{
        layer.msg("你没有选择行或选择了多行数据", {
            icon : 0
        });
    }
}
function btnEditState(){
    var rows = grid.getCheckedRecords();
    if (rows.length == 1) {
        loadPage('deviceInformation/'+rows[0].id+'/editState');
    }else{
        layer.msg("你没有选择行或选择了多行数据", {
            icon : 0
        });
    }
}

function btnAddDeviceImg(){
    var rows = grid.getCheckedRecords();
    if (rows.length == 1) {
        loadPage('deviceInformation/'+rows[0].id+'/addDeviceImg');
    }else{
        layer.msg("你没有选择行或选择了多行数据", {
            icon : 0
        });
    }
}

function btnAddUserImg(){
    var rows = grid.getCheckedRecords();
    if (rows.length == 1) {
        loadPage('deviceInformation/'+rows[0].id+'/addUserImg');
    }else{
        layer.msg("你没有选择行或选择了多行数据", {
            icon : 0
        });
    }
}

// function ok1(){
//     grid.parameters = new Object();
//     grid.parameters['factory_num'] = $("#factoryNum").val();
//     console.log("++++++"+$("#factoryNum").val());
//     grid.refresh(true);
// }
//
// function ok2(){
//     grid.parameters = new Object();
//     grid.parameters['identification'] = $("#identification").val();
//     grid.refresh(true);
// }